package com.sunwayhorizo.health.hl7.persistent;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.persistent.pk.RimCoreActRelationsPK;
import com.sunwayhorizo.health.hl7.rim.Act;

@Entity
@TableGenerator(name = "ActRelation_IdGenerator", table = "RIM_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn", pkColumnValue = "ActRelation_Id")
// @NamedQuery(name = "ActRelations.findAll",query =
// "select o from ActRelations o")
//@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PARTITION_BY_CLASS", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("RimCoreActRelations")
@Table(name = "RIM_CORE_ACT_RELATIONS")
@IdClass(RimCoreActRelationsPK.class)
public class RimCoreActRelations implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "ActRelation_IdGenerator")
	@Column(name = "RELATIONSHIP_ID", nullable = false)
	private Long relationshipId;
	
	@Column(name = "TYPE_CODE", nullable = false)
	protected String typeCode;
	
	@Column(name = "SPLIT_CODE")
    protected String splitCode;


	/*@Id
	@Column(name = "SOURCE_ACT_VER_NUM", nullable = false, insertable = false, updatable = false)
	private Long sourceActVerNum;
	@Id
	@Column(name = "TARGET_ACT_VER_NUM", nullable = false, insertable = false, updatable = false)
	private Long targetActVerNum;*/

	// ��controlact ά��
	@ManyToOne
	@JoinColumns({
			@JoinColumn(name = "CNTRL_ACT_ID", referencedColumnName = "ACT_ID"),
			@JoinColumn(name = "CNTRL_ACT_VERSION_NUM", referencedColumnName = "ACT_VERSION_NUM") })
	private RimCoreActs controlAct;

	// ��act ά����sourceAct��targetAct
	@ManyToOne
	@JoinColumns({
			@JoinColumn(name = "SOURCE_ACT_ID", referencedColumnName = "ACT_ID"),
			@JoinColumn(name = "SOURCE_ACT_VER_NUM", referencedColumnName = "ACT_VERSION_NUM") })
	private RimCoreActs sourceAct;

	@ManyToOne
	@JoinColumns({
			@JoinColumn(name = "TARGET_ACT_ID", referencedColumnName = "ACT_ID"),
			@JoinColumn(name = "TARGET_ACT_VER_NUM", referencedColumnName = "ACT_VERSION_NUM") })
	private RimCoreActs targetAct;

	public RimCoreActRelations() {
	}

	/*private Long getSourceActVerNum() {
		return sourceActVerNum;
	}

	private void setSourceActVerNum(Long sourceActVerNum) {
		this.sourceActVerNum = sourceActVerNum;
	}

	private Long getTargetActVerNum() {
		return targetActVerNum;
	}

	private void setTargetActVerNum(Long targetActVerNum) {
		this.targetActVerNum = targetActVerNum;
	}*/

	public RimCoreActs getSourceAct() {
		return sourceAct;
	}

	public void setSourceAct(RimCoreActs sourceAct) {
		this.sourceAct = sourceAct;
	}

	public RimCoreActs getTargetAct() {
		return targetAct;
	}

	public void setTargetAct(RimCoreActs targetAct) {
		this.targetAct = targetAct;
	}

	public void setControlAct(RimCoreActs controlAct) {
		this.controlAct = controlAct;
	}

	public RimCoreActs getControlAct() {
		return controlAct;
	}


}
